package com.zkool.train.exception;

import com.zkool.train.util.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Created by zhaokui on 2019/8/11.
 */
@RestControllerAdvice
public class ServiceExceptionHandler {

    private Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * 自定义异常
     */
    @ExceptionHandler(ServiceException.class)
    public R handleRRException(ServiceException e){
        logger.error(e.getMessage(), e);
        return R.error(e.getCode(), e.getMessage());
    }

}
